/**
 * 
 */
package com.et114.modules.products.search;


import org.compass.core.CompassCallback;
import org.compass.core.CompassSession;
import org.springframework.util.Assert;

import com.et114.components.compass.BaseCompassSupport;
import com.et114.components.simpletable.DataList;

/*
 * @author guanhw
 */
public class SearchService extends BaseCompassSupport {

	@ SuppressWarnings ( "unchecked" )
	public DataList  search ( String key , int pageNum ,
			int pageSize ) throws Exception {
		Assert.notNull ( key , "key is NULL !" );
		return ( DataList  ) getCompassTemplate ( ).execute (
				new SearchResultCallback ( key , pageNum , pageSize ) );
	}
	
	
	  @ SuppressWarnings ( "unchecked" )
	public SearchVo getPro( final Long proId , final Byte proType ) {
		  SearchVo numberOfHits = ( SearchVo )getCompassTemplate().execute(
	           new CompassCallback() {
	               public Object doInCompass( CompassSession session ) {
	            	   return session.get ( SearchVo.class , proId , proType ) ; 
	               }
	           }
	       );
	       
	       return numberOfHits ; 
	    }

	  public void setPro(  final Long proId , final Byte proType , final SearchVo vo ) {
		  getCompassTemplate().save ( vo ) ; 
		/*
		 * getCompassTemplate().execute( new CompassCallback() { public Object
		 * doInCompass( CompassSession session ) { session.save ( vo ) ; return
		 * null ; } } );
		 */
	  }

	  
	  public void removePro( final Long proId , final Byte proType ) {
		  getCompassTemplate().delete ( SearchVo.class , proId , proType ) ;
		/*
		 * getCompassTemplate().execute( new CompassCallback() { public Object
		 * doInCompass( CompassSession session ) { session.delete (
		 * SearchVo.class , proId , proType ) ; return null ; } } );
		 */
	  }
	  
	  
	  public void saveUpdate( final Long proId , final Byte proType , final SearchVo vo ) {
		  
	  }
}
